package com.woniuxy.joylife.manager.controller;

import com.woniuxy.common.constant.ManagerConstant;
import com.woniuxy.common.utils.KeyUtil;
import com.woniuxy.common.validate.AddGroup;
import com.woniuxy.joylife.manager.entity.EventEntity;
import com.woniuxy.joylife.manager.service.EventService;
import com.woniuxy.joylife.manager.utils.PageUtils;
import com.woniuxy.joylife.manager.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 重大事件
 *
 * @author renxiang
 * @email 981405195@qq.com
 * @date 2020-05-13 02:47:54
 */
@RestController
@RequestMapping("manager/event")
public class EventController {
    @Autowired
    private EventService eventService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("manager:event:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = eventService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{eventId}")
    //@RequiresPermissions("manager:event:info")
    public R info(@PathVariable("eventId") String eventId){
		EventEntity event = eventService.getById(eventId);

        return R.ok().put("event", event);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("manager:event:save")
    public R save(@Validated({AddGroup.class}) @RequestBody EventEntity event){
        event.setState(ManagerConstant.UNDELETED);
        event.setEventId(KeyUtil.generateKey());
		eventService.save(event);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("manager:event:update")
    public R update(@RequestBody EventEntity event){
        event.setUpdatetime(new Date());
		eventService.updateById(event);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("manager:event:delete")
    public R delete(@RequestBody String[] eventIds){
		eventService.removeByIds(Arrays.asList(eventIds));

        return R.ok();
    }

}
